//
//  PersonalHeaderView.swift
//  TrafficViolation
//
//  Created by eaglelive on 2017/4/12.
//  Copyright © 2017年 eaglelive. All rights reserved.
//

import UIKit

class PersonalHeaderView:UIView {
    var nickName = ""
    var icon = ""
    override func layoutSubviews() {
        super.layoutSubviews()
        // 背景视图
        let backImageView = UIImageView(image: UIImage(named: "person_bg2"))
        backImageView.frame = CGRect(x: 0, y: 0, width: sd_width, height: sd_height)
        backImageView.contentMode = .scaleToFill
        backImageView.layer.masksToBounds = true
        self.addSubview(backImageView)
    
        let btn = UIButton(type: .custom)
        btn.setTitleColor(UIColor.white, for: .normal)
        btn.setTitle(nickName, for: .normal)
        btn.titleLabel?.font = UIFont.systemFont(ofSize: 13)
        btn.backgroundColor = UIColor.red
        btn.showsTouchWhenHighlighted = true
        btn.layer.cornerRadius = 5
        let pvc = PersonalViewController()
        btn.addTarget(pvc, action: #selector(pvc.btnClick(sender:)), for: UIControlEvents.touchUpInside)
        self.addSubview(btn)
        btn.snp.makeConstraints { (make) in
            make.height.equalTo(20)
            make.width.equalTo(70)
            make.centerX.equalTo(backImageView.snp.centerX)
            make.bottom.equalTo(backImageView.snp.bottom).offset(-10)
        }
        let img = UIImageView()//个人图像
        let url = "\(projectUrl)/file/download/\(icon)?tokenID=\(tokenID!)&tokenUserID=\(userID!)"
        img.sd_setImage(with: URL.init(string: url), placeholderImage: UIImage.init(named: "personal_default"))
        img.layer.cornerRadius = 35.0
        img.layer.masksToBounds = true
        img.layer.borderColor = UIColor.white.cgColor
        img.layer.borderWidth = 2.0
        img.layer.rasterizationScale = UIScreen.main.scale
        img.layer.shouldRasterize = true
        self.addSubview(img)
        img.snp.makeConstraints { (make) in
            make.centerX.equalTo(backImageView.snp.centerX)
            make.bottom.equalTo(btn.snp.top).offset(-10)
            make.width.height.equalTo(70)
        }
    }
}

